﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Model
{
    public class UserManageRoleDetail
    {
        private DBUtil DB;
        public string strConn { get; set; }
        public int user_role_id { get; set; }
        public int user_id { get; set; }
        public int role_id { get; set; }
        public string role_name { get; set; }

        public UserManageRoleDetail()
        {
            this.DB = new DBUtil();
            DB.strConn = strConn;
        }

        public DataTable getByObject(UserManageRoleDetail obj)
        {

            DataTable dt = new DataTable();
            this.DB = new DBUtil();
            DB.strConn = strConn;

            string sql = "SELECT * FROM tcdc_mst_user_role_detail d, tcdc_mst_role r " +
                         "WHERE d.role_id = r.role_id ";

            if (obj.user_role_id != null &&
               obj.user_role_id.ToString() != null &&
               obj.user_role_id.ToString() != "0")
            {
                sql += "AND user_role_id LIKE '%" + obj.user_role_id + "%' ";
            }
            if (obj.user_id != null &&
               obj.user_id.ToString() != null &&
               obj.user_id.ToString() != "0")
            {
                sql += "AND user_id LIKE '%" + obj.user_id + "%' ";
            }
            if (obj.role_id != null &&
               obj.role_id.ToString() != null &&
               obj.role_id.ToString() != "0")
            {
                sql += "AND d.role_id LIKE '%" + obj.role_id + "%' ";
            }

            if (obj.role_name != null &&
             obj.role_name.ToString() != null &&
             obj.role_name.ToString() != "0")
            {
                sql += "AND role_name LIKE '%" + obj.role_name + "%' ";
            }
           
            dt = DB.ExecuteReader(sql);

            return dt;

        }
    }
}
